#coding:utf8
import pika
import json

file=open("E:\\vuser-test.txt")
rabbitmq_host='192.168.3.161'

# file=open("E:\\vuser.txt")
# rabbitmq_host='192.168.3.161'

rabbitmq_queue_name='python-demo-standard-server.unicastmessage.queue'
unicastMessage = {'to_uid':45796,
                  'type': 15,
                  'message_content':'做好声音赚大钱！上线一周，狂赚千万，大咖马东已玩嗨~付费收听计划等你加盟啦',
                  'titile':'喜马拉雅FM',
                  'url':'http://form.mikecrm.com/3ywIzs'}
connection = pika.BlockingConnection(pika.ConnectionParameters(
               rabbitmq_host))
channel = connection.channel()
channel.queue_declare(queue=rabbitmq_queue_name, durable=True)
while 1:
    line = file.readline()
    if not line:
        break
        pass
    if len(line) > 0:
        print line
        unicastMessage['to_uid'] = int(line)
        json_body=json.dumps(unicastMessage)
        channel.basic_publish(exchange='', routing_key=rabbitmq_queue_name,body=json_body, properties = pika.BasicProperties(
                              content_type ="text/plain"
                           ))
connection.close()
print "end"
